package com.pengcheng.taskapplication.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.helper.ImageLoader;
import com.pengcheng.taskapplication.model.NoticeModel;
import com.pengcheng.taskapplication.model.ParkOrderModel;
import com.pengcheng.taskapplication.mvp.view.widget.CircleImageView;
import com.pengcheng.taskapplication.mvp.view.widget.RoundCornerImageView;
import com.pengcheng.taskapplication.net.ConvertUtil;
import com.pengcheng.taskapplication.util.DisplayHelper;
import com.sina.weibo.sdk.utils.ImageUtils;

import java.text.DecimalFormat;
import java.util.List;

public class NoticeAdapter extends BaseAdapter {

	Context context;
	LayoutInflater inflater;
	List<NoticeModel> noticeModels;
	int last_item;
	private int selectedPosition = -1;
	public NoticeAdapter(Context context, List<NoticeModel> noticeModels){
		this.context = context;
		this.noticeModels = noticeModels;
		inflater= LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return noticeModels.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return noticeModels.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder  holder = null;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.fragment_notice_list_item_layout, null);
			holder = new ViewHolder();
			holder.img_left=(RoundCornerImageView) convertView.findViewById(R.id.img_left);
			holder.tv_content=(TextView)convertView.findViewById(R.id.tv_content);
			holder.tv_title=(TextView)convertView.findViewById(R.id.tv_title);
			convertView.setTag(holder);
		}
		else{
			holder=(ViewHolder)convertView.getTag();
		}

		NoticeModel model= noticeModels.get(position);
		holder.tv_title.setText(model.getTitle()+"");
		holder.tv_content.setText(model.getContent());
		ImageLoader.displayImage(context,model.getImg(),
				(ImageView)holder.img_left);
		return convertView;
	}

	public static class ViewHolder{
		public TextView tv_title;
		public TextView tv_content;
		public RoundCornerImageView img_left;

	}

	public void setSelectedPosition(int position) {
		selectedPosition = position;
	}

}
